﻿var lastAccessedTime = new Date();
// Write your JavaScript code.
function newGuid(){
    function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    }
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
// 将string转为UTF-8格式signed char字节数组
function str2UTF8(str) {
    var bytes = new Array();
    var len, c;
    len = str.length;
    for (var i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if (c >= 0x010000 && c <= 0x10FFFF) {
            bytes.push(((c >> 18) & 0x07) | 0xF0);
            bytes.push(((c >> 12) & 0x3F) | 0x80);
            bytes.push(((c >> 6) & 0x3F) | 0x80);
            bytes.push((c & 0x3F) | 0x80);
        } else if (c >= 0x000800 && c <= 0x00FFFF) {
            bytes.push(((c >> 12) & 0x0F) | 0xE0);
            bytes.push(((c >> 6) & 0x3F) | 0x80);
            bytes.push((c & 0x3F) | 0x80);
        } else if (c >= 0x000080 && c <= 0x0007FF) {
            bytes.push(((c >> 6) & 0x1F) | 0xC0);
            bytes.push((c & 0x3F) | 0x80);
        } else {
            bytes.push(c & 0xFF);
        }
    }
    return bytes;
}
// 将整数转换为16进制字符，digital：位数（默认2），不足前补零
function intToHex(i, digital) {
    var s = i.toString(16);
    var zero = digital == undefined ? s.length % 2 : digital - (s.lenght % digital);
    return "0000000000".substring(0, zero) + s;
}
// byte数组转字符串
function byteToString(arr) {
    if (typeof arr === 'string') {
        return arr;
    }
    var str = '',
        _arr = arr;
    for (var i = 0; i < _arr.length; i++) {
        var one = _arr[i].toString(2),
            v = one.match(/^1+?(?=0)/);
        if (v && one.length == 8) {
            var bytesLength = v[0].length;
            var store = _arr[i].toString(2).slice(7 - bytesLength);
            for (var st = 1; st < bytesLength; st++) {
                store += _arr[st + i].toString(2).slice(2);
            }
            str += String.fromCharCode(parseInt(store, 2));
            i += bytesLength - 1;
        } else {
            str += String.fromCharCode(_arr[i]);
        }
    }
    return str;
}
// 获取文件后缀，返回值包含.
function getFileExt(filename) {
    var idx = filename.lastIndexOf(".");
    return filename.substr(idx);
}
// 获取本地文件URL路径，用于查看选择的文件
function getLocalURL(file) {
    var url = null;
    if (window.createObjectURL !== undefined) {
        url = window.createObjectURL(file);
    } else if (window.URL !== undefined) { // mozilla(firefox)  
        url = window.URL.createObjectURL(file);
    } else if (window.webkitURL !== undefined) { // webkit or chrome  
        url = window.webkitURL.createObjectURL(file);
    }
    return url;
}
// 将本地图片文件显示到img控件中
function viewImageFile(img, file) {
    $("#" + img).attr("src", getLocalURL(file));
}
// 将B64码图片数据显示到img控件中
function viewImageData(img, D64) {
    var src = (D64.indexOf("data:image/") == 0) ? D64 : "data:image/jpeg;base64," + D64;
    $("#" + img).attr("src", src);
}
// 将图片控件中的图形转换为B64码格式数据
function getImageData(img) {
    var imgTag = $("#" + img)[0];
    if (imgTag.src.indexOf("data:image/") == 0) return imgTag.src;
    else {
        var canvas = document.createElement("canvas");
        canvas.width = imgTag.width;
        canvas.height = imgTag.height;
        var ctx = canvas.getContext("2d");
        ctx.drawImage(imgTag, 0, 0, imgTag.width, imgTag.height);
        var ext = imgTag.src.substring(imgTag.src.lastIndexOf(".") + 1).toLowerCase();
        var dataUrl = canvas.toDataURL("images/" + ext);
        return dataUrl;
    }
}
// r,g,b范围为[0,255],转换成h范围为[0,360]
// s,l为百分比形式，范围是[0,100],可根据需求做相应调整
function rgbToHsl(r, g, b) {
    r = r / 255;
    g = g / 255;
    b = b / 255;
    var min = Math.min(r, g, b);
    var max = Math.max(r, g, b);
    var l = (min + max) / 2;
    var difference = max - min;
    var h, s, l;
    if (max == min) {
        h = 0;
        s = 0;
    } else {
        s = l > 0.5 ? difference / (2.0 - max - min) : difference / (max + min);
        switch (max) {
            case r: h = (g - b) / difference + (g < b ? 6 : 0); break;
            case g: h = 2.0 + (b - r) / difference; break;
            case b: h = 4.0 + (r - g) / difference; break;
        }
        h = Math.round(h * 60);
    }
    s = Math.round(s * 100);//转换成百分比的形式
    l = Math.round(l * 100);
    return [h, s, l];
}
// r,g,b范围为[0,255],转换成h范围为[0,360]
// s,v为百分比形式，范围是[0,100],可根据需求做相应调整
function rgbToHsv(r, g, b) {
    r = r / 255;
    g = g / 255;
    b = b / 255;
    var h, s, v;
    var min = Math.min(r, g, b);
    var max = v = Math.max(r, g, b);
    var l = (min + max) / 2;
    var difference = max - min;

    if (max == min) {
        h = 0;
    } else {
        switch (max) {
            case r: h = (g - b) / difference + (g < b ? 6 : 0); break;
            case g: h = 2.0 + (b - r) / difference; break;
            case b: h = 4.0 + (r - g) / difference; break;
        }
        h = Math.round(h * 60);
    }
    if (max == 0) {
        s = 0;
    } else {
        s = 1 - min / max;
    }
    s = Math.round(s * 100);
    v = Math.round(v * 100);
    return [h, s, v];
}
//输入的h范围为[0,360],s,l为百分比形式的数值,范围是[0,100] 
//输出r,g,b范围为[0,255],可根据需求做相应调整
function hslToRgb(h, s, l) {
    var h = h / 360;
    var s = s / 100;
    var l = l / 100;
    var rgb = [];

    if (s == 0) {
        rgb = [Math.round(l * 255), Math.round(l * 255), Math.round(l * 255)];
    } else {
        var q = l >= 0.5 ? (l + s - l * s) : (l * (1 + s));
        var p = 2 * l - q;
        var tr = rgb[0] = h + 1 / 3;
        var tg = rgb[1] = h;
        var tb = rgb[2] = h - 1 / 3;
        for (var i = 0; i < rgb.length; i++) {
            var tc = rgb[i];
            console.log(tc);
            if (tc < 0) {
                tc = tc + 1;
            } else if (tc > 1) {
                tc = tc - 1;
            }
            switch (true) {
                case (tc < (1 / 6)):
                    tc = p + (q - p) * 6 * tc;
                    break;
                case ((1 / 6) <= tc && tc < 0.5):
                    tc = q;
                    break;
                case (0.5 <= tc && tc < (2 / 3)):
                    tc = p + (q - p) * (4 - 6 * tc);
                    break;
                default:
                    tc = p;
                    break;
            }
            rgb[i] = Math.round(tc * 255);
        }
    }

    return rgb;
}
//输入的h范围为[0,360],s,l为百分比形式的数值,范围是[0,100] 
//输出r,g,b范围为[0,255],可根据需求做相应调整
function hsvToRgb(h, s, v) {
    var s = s / 100;
    var v = v / 100;
    var h1 = Math.floor(h / 60) % 6;
    var f = h / 60 - h1;
    var p = v * (1 - s);
    var q = v * (1 - f * s);
    var t = v * (1 - (1 - f) * s);
    var r, g, b;
    switch (h1) {
        case 0:
            r = v;
            g = t;
            b = p;
            break;
        case 1:
            r = q;
            g = v;
            b = p;
            break;
        case 2:
            r = p;
            g = v;
            b = t;
            break;
        case 3:
            r = p;
            g = q;
            b = v;
            break;
        case 4:
            r = t;
            g = p;
            b = v;
            break;
        case 5:
            r = v;
            g = p;
            b = q;
            break;
    }
    return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
}
// RGB颜色转换为网页颜色值，含#开头
function rgbToColor(r, g, b) {
    return "#" + intToHex(r) + intToHex(g) + intToHex(b);
}
// 系列色起始颜色初始值
var rgb = [224, 204, 255];
//取得下一个以起始色为基色的系列颜色，part为基本等分份数
function getNextColor(part) {
    var hsl = rgbToHsl(rgb[0], rgb[1], rgb[2]);
    var rate = Math.round(360 / (part * 2 + 1)) * 2;
    hsl[0] = (hsl[0] + rate) % 360;
    rgb = hslToRgb(hsl[0], hsl[1], hsl[2]);
    return rgbToColor(rgb[0], rgb[1], rgb[2]);
}
//取得当前系列色中适合的字体颜色，含#开头
function getFontColor(r) {
    if (r == undefined) r = rgb;
    if (0.213 * r[0] + 0.715 * r[1] + 0.072 * r[2] > 255 / 2) return "#000"; else return "#FFF";
}
// 动态加载js文件
var javascript_files = [];
function addJavascriptFile(file) {
    var found = javascript_files.filter(function (d) {
        return d == file;
    });
    if(found.length == 0)
        $.getScript(file, function () {
            javascript_files.push(file);
        });
}
// 移动数据在JSON数组中的位置，arr:数组, src:原始位置, dest:目标位置
function arrayMove(arr, src, dest) {
    if (src < 0 || src > arr.lenght) return;
    if (dest < 0 || dest > arr.lenght) return;
    var item = arr.splice(src, 1);
    arr.splice(dest, 0, item);
}
// 移动元素在页面中的位置，tag:元素，例如："#AA", dest:目标位置（序号或方向，如“top,up,down,bottom”或“t,u,d,b”）
function moveTag(tag, dest) {
    if (typeof (dest) == "string") {
        if (dest.toLowerCase() == "top" || dest.toLowerCase() == "t") $(tag).siblings().eq(0).before($(tag));
        else if (dest.toLowerCase() == "up" || dest.toLowerCase() == "u") {
            var idx = $(tag).index();
            if (idx > 0) $(tag).siblings().eq(idx - 1).before($(tag));
        }
        else if (dest.toLowerCase() == "down" || dest.toLowerCase() == "d") {
            var idx = $(tag).index();
            $(tag).siblings().eq(idx).after($(tag));
        }
        else if (dest.toLowerCase() == "bottom" || dest.toLowerCase() == "b") {
            $(tag).siblings().last().after($(tag));
        }
    }
    else if (dest == 0) $(tag).siblings().eq(dest).before($(tag));
    else $(tag).siblings().eq(dest).after($(tag));
}
// 格式化日期y：年，M：月，d：日，h：小时，m：分钟，s：秒，w：星期
function dateFormat(fmt, date) {
    let ret;
    const opt = {
        "y+": date.getFullYear().toString(),        // 年
        "M+": (date.getMonth() + 1).toString(),     // 月
        "d+": date.getDate().toString(),            // 日
        "h+": date.getHours().toString(),           // 时
        "m+": date.getMinutes().toString(),         // 分
        "s+": date.getSeconds().toString(),         // 秒
        "w+": "星期" + ("日一二三四五六".substr(date.getDay(), 1))
    };
    for (let k in opt) {
        ret = new RegExp("(" + k + ")").exec(fmt);
        if (ret) {
            fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
        };
    };
    return fmt;
}
// Ajax functions to access service
function SysWarning(s) {
    if (s === null || s === undefined) {
        $('#alert_message').popover('hide');
    }
    else {
        var m = $("#StatusMessage");
        if (m.lenght > 0) {
            $(m).text(s);
        }
        else {
            m = $('#alert_message');
            m.attr("title", "系统警告");
            m.attr("data-content", s);
            m.popover('show');
            setTimeout("closeSysWarning()", "2000");
        }
    }
}
function closeSysWarning() {
    $("#alert_message").popover('hide');
}
function AjaxSendData(tp, actionUrl, params, fn, errfn) {
    lastAccessedTime = new Date();
    $.ajax(
        {
            url: actionUrl, data: {
                "data": JSON.stringify(params)
            },
            //将表单数据序列化，格式为name=value
            type: tp, dataType: 'json',
            success: function (result) {
                lastAccessedTime = new Date();
                if (result.hasOwnProperty("Success")) {
                    closeSysWarning();
                    if (result.hasOwnProperty("Result")) fn(result["Success"], result["Result"]);
                    else fn(result["Success"]);
                }
                else {
                    if (errfn == null || errfn == undefined)
                        SysWarning(result["Error"]);
                    else errfn(result["Error"]);
                }
            },
            error: function (result) {
                lastAccessedTime = new Date();
                if (errfn == null || errfn == undefined)
                    SysWarning("申请失败，请重试.");
                else errfn(result["Error"]);
            }
        });
}
function AjaxPostData(actionUrl, params, fn, errfn) {
    AjaxSendData("POST", actionUrl, params, fn, errfn);
}
function AjaxGetData(actionUrl, params, fn, errfn) {
    AjaxSendData("GET", actionUrl, params, fn, errfn);
}
function AjaxSendForm(tp, actionUrl, formData, fn, errfn) {
    lastAccessedTime = new Date();
    $.ajax(
        {
            url: actionUrl, data: formData, //将表单数据序列化，格式为name=value
            type: tp, processData: false, contentType: false, async: false,
            success: function (result) {
                lastAccessedTime = new Date();
                if (result.hasOwnProperty("Success")) {
                    closeSysWarning();
                    fn(result["Success"]);
                }
                else {
                    if (errfn == null || errfn == undefined)
                        SysWarning(result["Error"]);
                    else errfn(result["Error"]);
                }
            },
            error: function () {
                lastAccessedTime = new Date();
                if (errfn == null || errfn == undefined)
                    SysWarning("申请失败，请重试.");
                else errfn(result["Error"]);
            }
        });
}
// function to update row of table
VonEditor = function (appname) {
    this.app = appname;
    this.__proto__ = {
        get mode() { return $("#" + this.app + "Editor").attr("data-mode"); },
        set mode(value) { return $("#" + this.app + "Editor").attr("data-mode", value); }
    };
    this.display = function (mode) {
        $("#" + this.app + "Editor").attr("data-mode", mode);
        $("#" + this.app + "Editor").modal("show");
    };
    this.close = function () {
        $("" + this.app + "Editor").removeAttr("data-mode");
        $("#" + this.app + "Editor").modal("hide");
    };
    // 存储字段名称集合
    this.fields = [];
    // 清除编辑框内容调用函数
    this.clear = function () {
        for (var i in this.fields) {
            $("#" + this.app + "Editor").find("#" + this.fields[i]).val("");
        }
    };
    // 设置编辑框内容调用函数
    this.setData = function (data) {
        for (var i in this.fields) {
            $("#" + this.app + "Editor").find("#" + this.fields[i]).val(data[this.fields[i]]);
        }
    };
    // 获取编辑框内容调用函数
    this.getData = function (data) {
        for (var i in this.fields) {
            var tag = $("#" + this.app + "Editor").find("#" + this.fields[i]);
            if (tag.length > 0) data[this.fields[i]] = tag.val();
        }
    };
}
function Von_Selector(appname) {
    var app = appname;
    this.selectRow = function (btn) {
        $("[data-" + app + "-sel=true]").removeAttr("data-" + app + "-sel");
        if (btn !== null) {
            var result = $(btn).parents("tr:first");
            $(result).attr("data-" + app + "-sel", true);
            return result;
        } else return null;
    };
    this.insertRow = function (html) {
        $("[data-" + app + "-sel=true]").before(html);
    };
    this.appendRow = function (html) {
        $("#" + app + "List tbody").append(html);
    };
    this.replaceRow = function (html) {
        $("[data-" + app + "-sel=true]").replaceWith(html);
    };
    this.deleteRow = function () {
        $("[data-" + app + "-sel=true]").remove();
    };
    this.currentRow = function () {
        return $("[data-" + app + "-sel=true] td");
    };
    this.currentCell = function (col) {
        return $("[data-" + app + "-sel=true] td").eq(col);
    };
    this.row_html = "", this.btn_html = "";
    this.addCell = function (html) {
        this.row_html += "<td>" + html + "</td>";
    };
    this.addCol = function (html) {
        this.row_html += html;
    };
    this.addUrl = function (url, text, btnStyle) {
        if (url.substring(0, 1) !== "/") {
            var l = window.location.href;
            var index = l.lastIndexOf("\/");
            url = index < 0 ? url : window.location.href.substring(0, index + 1) + url;
        }
        this.btn_html += (this.btn_html === "" ? "" : " | ") + "<a href=\"" + url + "\" class=\"btn btn-xs btn-" + (btnStyle === undefined ? "link" : btnStyle) + "\" target=\"_blank\">" + text + "</a>";
    };
    this.addBtn = function (item, fuName, text, btnStyle) {
        this.btn_html += (this.btn_html === "" ? "" : " | ") + "<input type='button' class='btn btn-xs btn-" + btnStyle + "' onclick=\"" + fuName + "(this,'" + item + "')\" value='" + text + "' />";
    };
    this.addStyleBtn = function (item, fuName, text, style) {
        this.btn_html += (this.btn_html === "" ? "" : " | ") + "<input type='button' style='" + style + "' onclick=\"" + fuName + "(this,'" + item + "')\" value='" + text + "' />";
    };
    this.addPrimary = function (item, fuName, text) {
        this.addBtn(item, fuName, text, "primary");
    };
    this.addSuccess = function (item, fuName, text) {
        this.addBtn(item, fuName, text, "success");
    };
    this.addInfo = function (item, fuName, text) {
        this.addBtn(item, fuName, text, "info");
    };
    this.addLink = function (item, fuName, text) {
        this.addBtn(item, fuName, text, "link");
    };
    this.addDanger = function (item, fuName, text) {
        this.addBtn(item, fuName, text, "danger");
    };
    this.addWarning = function (item, fuName, text) {
        this.addBtn(item, fuName, text, "warning");
    };
    this.addAction = function (area, controller, action, text) {
        this.btn_html += (this.btn_html === "" ? "" : " | ") + "<a href=\"/" + (area === "" ? "" : area + "/") + controller + "/" + action + "\" class=\"btn btn-xs btn-link\" target=\"_blank\">" + text + "</a>";
    };
    this.clearRow = function () {
        this.row_html = "";
        this.btn_html = "";
    };
    this.getHtml = function (data) {
        this.clearRow();
        this.onAddFields(data);
        this.onAddBtns(data);
        return "<tr>" + this.row_html + (this.btn_html !== "" ? "<td>" + this.btn_html + "</td>" : "") + "</tr>";
    };
}
// VonGrid 工厂模式创建函数，直接调用即可创建新实例，例如：var von=VonGrid({...option...});
VonGrid = function (options) {
    var tbl = new function () {
        // 应用名
        this.app = options["app"];
        // 主键
        this.keyName = "ID";
        // 显示字段名称集合
        this.displayFields = [];
        this.clearTable = function () {
            $("#" + this.app + "List tbody tr").remove();
        };
        this.appendTable = function (datas) {
            for (var i = 0; i < datas.length; i++) {
                this.appendRow(this.getHtml(datas[i]));
            }
        };
        // 添加行信息显示字段调用函数
        this.onAddFields = function (data) {
            for (var i in this.displayFields) {
                this.addCell(data[this.displayFields[i]]);
            }
        };
        // 添加行信息显示按钮调用函数
        this.onAddBtns = function (data) {
            this.addLink(data[this.keyName], "Edit" + this.app, "编辑");
            this.addDanger(data[this.keyName], "Delete" + this.app, "删除");
        };
        Von_Selector.call(this, this.app);
        //-------------------------------------
    };
    tbl.von = tbl;
    // 合并系统选项
    for (key in options) {
        if (options[key] !== undefined) {
            tbl[key] = options[key];
        }
    }
    tbl.editor = new VonEditor(tbl.app);
    tbl.editor.fields = options.fields;
    return tbl;
}
// 采用bootstrap list-group 样式，采用 a 节点实现列表，支持 badge 图标和点击事件。
VonActionList = function (options) {
    var lst = new function () {
        // 应用名
        this.app = "von";
        // 主键字段名
        this.keyName = "ID";
        // 标题字段名
        this.title = "ID";
        this.selected = function () {
            return $("#" + this.app + "List .active");
        };
        this.onImage = function (data) {
            return "";
        };
        this.onClick = function (data) {
            return "select" + this.app + "(this, '" + data[this.keyName] + "')";
        };
        this.onGetItem = function (data) {
            var img = this.onImage(data);
            if (img !== "") img = "<span class=\"badge\">" + img + "</span>";
            var clk = this.onClick(data);
            return "<a class=\"list-group-item\" onclick=\"" + clk + "\">" + img + data[this.title] + "</a>";
        };
        this.clear = function () {
            $("#" + this.app + "List").children().remove();
        };
        this.insert = function (html) {
            $("#" + this.app + "List .active").before(html);
        };
        this.remove = function () {
            $("#" + this.app + "List .active").remove();
        };
        this.append = function (html) {
            $("#" + this.app + "List").append(html);
        };
        this.replace = function (html) {
            $("#" + this.app + "List .active").replaceWith(html).addClass("active");
        };
        this.select = function (item) {
            $("#" + this.app + "List .list-group-item").removeClass("active");
            $(item).addClass("active");
        };
        this.getHtml = function (data) { return this.onGetItem(data); };
    };
    // 合并系统选项
    for (key in options) {
        if (options[key] !== undefined) {
            lst[key] = options[key];
        }
    }
    return lst;
}
// VonTreeGrid 工厂模式创建函数，直接调用即可创建新实例，例如：var von=VonTreeGrid({...option...});
VonTreeGrid = function (options) {
    var treeGuid = new function () {
        // 应用名
        this.app = "von";
        // 主键
        this.keyName = "ID";
        this.parentName = "PID";
        this.orderName = "DisplayOrder";
        this.treeField = "catalog";
        // 显示字段名称集合
        this.displayFields = [];
        // 显示字段名称集合
        this.operateBtns = [
            { id: 'btnAdd', text: '添加同级节点', iconCls: 'icon-add', handler: function () { eval("add" + von.app + "('new')"); } }, '-',
            { id: 'btnAddChild', text: '添加下级节点', iconCls: 'icon-add', handler: function () { eval("add" + von.app + "('child')"); } }, '-',
            { id: 'btnEdit', text: '修改当前节点', iconCls: 'icon-edit', handler: function () { eval("edit" + von.app + "()"); } }, '-',
            { id: 'btnDel', text: '删除当前节点', iconCls: 'icon-cancel', handler: function () { eval("del" + von.app + "()"); } }, '-',
            { id: 'btnUp', text: '上移当前节点', iconCls: 'icon-up', handler: function () { eval("move" + von.app + "('up')"); } }, '-',
            { id: 'btnDown', text: '下移当前节点', iconCls: 'icon-down', handler: function () { eval("move" + von.app + "('down')"); } }, '-',
            { id: 'btnLeft', text: '左移当前节点', iconCls: 'icon-left', handler: function () { eval("move" + von.app + "('left')"); } }, '-',
            { id: 'btnRight', text: '右移当前节点', iconCls: 'icon-right', handler: function () { eval("move" + von.app + "('right')"); } }];
        // 存储字段名称集合
        this.fields = [];
        // 添加行信息显示字段调用函数
        this.onAddFields = function (data) {
            for (var i in this.displayFields) {
                this.addCell(data[this.displayFields[i]]);
            }
        };
        this.url2Load = "";
        // 初始化treeGrid
        this.init = function (url, pid) {
            this.url2Load = url;
            $('#' + this.app + 'Tree').treegrid({
                url: this.url2Load.replace(new RegExp("\\{0\\}"), pid),
                idField: this.keyName,
                treeField: this.treeField,
                rownumbers: true,
                columns: [this.displayFields],
                loadFilter: function (result) {
                    return result.hasOwnProperty("Success") ? result.Success : result;
                },
                onLoadSuccess: function (row, result) {
                    //if (row != undefined && row.children != undefined) row.state = "open";
                    //row.id = result.Code;
                    //row.pid = result.BaseCode;
                    //row.state = "closed";
                    //$('#' + von.app + 'Tree').treegrid('append', { parent: row === null ? null : row.ID, data: result.Success });
                }, onBeforeExpand: function (row) {
                    if (row.children == undefined)
                        $(this).treegrid('options').url = treeGuid.url2Load.replace(new RegExp("\\{0\\}"), row.Code);
                    return true;
                },
                toolbar: this.operateBtns
            });
        };
        // 初始化treeGrid
        this.load = function (data) {
            $('#' + this.app + 'Tree').treegrid({
                data: data,
                idField: this.keyName,
                treeField: this.treeField,
                rownumbers: true,
                columns: [this.displayFields],
                toolbar: this.operateBtns
            });
        };
        // 初始化treeGrid
        this.ajax = function (url, data) {
            AjaxPostData(url, data, function (result) {
                $('#' + this.app + 'Tree').treegrid({
                    data: result,
                    idField: this.keyName,
                    treeField: this.treeField,
                    rownumbers: true,
                    columns: [this.displayFields],
                    toolbar: this.operateBtns
                });
            });
        };
        // 获取同级节点集合
        this.getSiblings = function (node) {
            if ($('#' + this.app + 'Tree').treegrid('getParent', node[this.keyName]) === null)
                return $('#' + this.app + 'Tree').treegrid('getRoots');
            else
                return $('#' + this.app + 'Tree').treegrid('getParent', node[this.keyName]).children;
        };
        // 获取下级节点集合
        this.getChildren = function (node) {
            return $('#' + this.app + 'Tree').treegrid('getChildren', node[von.keyName]);
        };
        // 获取父级节点集合
        this.getParent = function (node) {
            return $('#' + this.app + 'Tree').treegrid('getParent', node[von.keyName]);
        };
        // 获取节点层级
        this.getLevel = function (node) {
            return $('#' + this.app + 'Tree').treegrid('getLevel', node[von.keyName]);
        };
        // 更新当前节点
        this.updateNode = function (id, data) {
            $('#' + this.app + 'Tree').treegrid('update', {
                id: id, row: data
            });
        };
        // 在id节点后添加一个新节点
        this.appendNode = function (pid, data) {
            if (pid === null || pid === undefined)
                $('#' + this.app + 'Tree').treegrid('append', { data: data });
            else
                $('#' + this.app + 'Tree').treegrid('append', { parent: pid, data: data });
        };
        // 移动当前节点位置，url:更新网址，way:移动方向（up,down,left,right）
        this.moveNode = function (url, way) {
            var node = this.currentNode;
            var nodes = this.getSiblings(node);
            var data = { ID: node[this.keyName] };
            if (way == "up") {
                if (node[this.orderName] == 0) return;
                data[this.orderName] = parseInt(node[this.orderName]) - 1;
                data[this.parentName] = node[this.parentName];
            } else if (way == "down") {
                if (node[this.orderName] >= nodes.length) return;
                data[this.orderName] = parseInt(node[this.orderName]) + 1;
                data[this.parentName] = node[this.parentName];
            } else if (way == "left") {
                var pnode = this.getParent(node);
                if (pnode == null) return;
                data[this.orderName] = 0;
                data[this.parentName] = pnode[this.parentName];
            } else if (way == "right") {
                if (node == null || parseInt(node[this.orderName]) == 0) return;
                data[this.orderName] = 0;
                data[this.parentName] = nodes[nodes.indexOf(node) - 1][this.keyName];
            }
            AjaxPostData(url, data,
                function (result) {
                    node[von.orderName] = result[von.orderName];
                    node[von.parentName] = result[von.parentName];
                    if (way == "up") {
                        var previous = nodes[nodes.indexOf(node) - 1];
                        var n2 = $('#' + von.app + 'Tree').treegrid("pop", node[von.keyName]);
                        $('#' + von.app + 'Tree').treegrid("insert", { before: previous[von.keyName], data: n2 });
                        $('#' + von.app + 'Tree').treegrid("select", node[von.keyName]);
                    } else if (way == "down") {
                        var n2 = $('#' + von.app + 'Tree').treegrid("pop", nodes[nodes.indexOf(node) + 1][von.keyName]);
                        $('#' + von.app + 'Tree').treegrid("insert", { before: node[von.keyName], data: n2 });
                    } else if (way == "left") {
                        var n2 = $('#' + von.app + 'Tree').treegrid("pop", node[von.keyName]);
                        n2[von.orderName] = result[von.orderName];
                        $('#' + von.app + 'Tree').treegrid("append", { parent: pnode[von.parentName], data: [n2] });
                    } else if (way == "right") {
                        var idx = nodes.indexOf(node);
                        var n2 = $('#' + von.app + 'Tree').treegrid("pop", node[von.keyName]);
                        n2[von.orderName] = result[von.orderName];
                        $('#' + von.app + 'Tree').treegrid("append", { parent: nodes[idx - 1][von.keyName], data: [n2] });
                    }
                    for (var n in nodes) nodes[n][von.orderName] = n;
                    nodes = von.getSiblings(node);
                    for (var n in nodes) nodes[n][von.orderName] = n;
                });
        };
        this.deleteNode = function (node) {
            $('#' + this.app + 'Tree').treegrid('remove', node[this.keyName]);
        };
        // 清除所有节点
        this.clear = function () {
            $('#' + this.app + 'Tree').treegrid('loadData', []);
        };
        this.__proto__ = {
            get currentNode() { return $('#' + this.app + 'Tree').treegrid('getSelected'); }
        };
    };
    treeGuid.von = treeGuid;
    // 合并系统选项
    for (key in options) {
        if (options[key] !== undefined) {
            treeGuid[key] = options[key];
        }
    }
    // 添加行信息显示按钮调用函数
    treeGuid.onAddBtns = function (data) {
        this.addLink(data[this.keyName], "Edit" + this.app, "编辑");
        this.addDanger(data[this.keyName], "Delete" + this.app, "删除");
    };
    treeGuid.editor = new VonEditor(treeGuid.app);
    treeGuid.editor.fields = options.fields;
    return treeGuid;
}
// VonTree 工厂模式创建函数，直接调用即可创建新实例，例如：var von=VonTree({...option...});
VonTree = function (option) {
    var tree = function (option) {
        this.instance = null;
        this.app = option.app;
        this.opt = option;
        this.url2Load = "";
        this.onFilter = function(data) {
            var opt = $(this).tree("options");
            function splitData(arr) {
                for (var a of arr) {
                    a.id = a[opt.keyName];
                    a.text = a[opt.treeField];
                    if (opt.iconField != undefined && opt.iconField != "") a.iconCls = opt.icons[a[opt.iconField]];
                    if (a.children != undefined) splitData(a.children);
                }
            }
            splitData(data);
            return data;
        };
        this.__proto__ = {
            get currentNode() { return $(this.tree).tree('getSelected'); }
        };
        // 获取同级节点集合
        this.selectNode = function(node) {
            $(this.tree).tree("select", node.target);
        }
        // 获取同级节点集合
        this.getSiblings = function(node) {
            var pnode = $(this.tree).tree('getParent', node.target);
            if (pnode === null) return $(this.tree).tree('getRoots');
            else return this.getChildren(pnode);
        };
        // 获取下级节点集合
        this.getChildren = function(node) {
            var subNodes = [];
            var t = this.tree;
            $(node.target).next().children().children("div.tree-node").each(function () {
                subNodes.push($(t).tree('getNode', this));
            });
            return subNodes;
        };
        // 获取父级节点集合
        this.getParent = function(node) {
            return $(this.tree).tree('getParent', node.target);
        };
        // 获取节点层级
        this.getLevel = function(node) {
            var l = $(node[this.opt.keyName]).parentsUntil("ul.tree", "ul");
            return l.length + 1;
        };
        // 更新当前节点
        this.updateNode = function(node, data) {
            $(this.tree).tree('update', {
                target: node.target, text: data[this.opt.treeField]
            });
        };
        // 在id节点后添加一个新节点
        this.appendNode = function(node, data) {
            if (node == null) $('#' + this.app + 'Tree').tree('append', { data: data });
            else $(this.tree).tree('append', { parent: node.target, data: data });
        };
        // 移动当前节点位置，url:更新网址，way:移动方向（up,down,left,right）
        this.moveNode = function(url, way) {
            var node = this.currentNode;
            var nodes = this.getSiblings(node);
            var data = { ID: node[this.keyName] };
            if (way == "up") {
                if (node[this.orderName] == 0) return;
                data[this.orderName] = node[this.orderName] - 1;
                data[this.parentName] = node[this.parentName];
            } else if (way == "down") {
                if (node[this.orderName] >= nodes.length) return;
                data[this.orderName] = node[this.orderName] + 1;
                data[this.parentName] = node[this.parentName];
            } else if (way == "left") {
                var pnode = this.getParent(node);
                if (pnode == null) return;
                data[this.orderName] = 0;
                data[this.parentName] = pnode[this.parentName];
            } else if (way == "right") {
                if (node == null || node[this.orderName] == 0) return;
                data[this.orderName] = 0;
                data[this.parentName] = nodes[nodes.indexOf(node) - 1][this.keyName];
            }
            AjaxPostData(url, data,
                function (result) {
                    node[this.orderName] = result[this.orderName];
                    node[this.parentName] = result[this.parentName];
                    if (way == "up") {
                        var previous = nodes[nodes.indexOf(node) - 1];
                        var n2 = $(this.tree).treegrid("pop", node[this.keyName]);
                        $(this.tree).treegrid("insert", { before: previous[this.keyName], data: n2 });
                        $(this.tree).treegrid("select", node[this.keyName]);
                    } else if (way == "down") {
                        var n2 = $(this.tree).treegrid("pop", nodes[nodes.indexOf(node) + 1][this.keyName]);
                        $(this.tree).treegrid("insert", { before: node[this.keyName], data: n2 });
                    } else if (way == "left") {
                        var n2 = $(this.tree).treegrid("pop", node[this.keyName]);
                        n2[this.orderName] = result[this.orderName];
                        $(this.tree).treegrid("append", { parent: pnode[this.parentName], data: [n2] });
                    } else if (way == "right") {
                        var idx = nodes.indexOf(node);
                        var n2 = $(this.tree).treegrid("pop", node[this.keyName]);
                        n2[this.orderName] = result[this.orderName];
                        $(this.tree).treegrid("append", { parent: nodes[idx - 1][this.keyName], data: [n2] });
                    }
                    for (var n in nodes) nodes[n][this.orderName] = n;
                    nodes = this.getSiblings(node);
                    for (var n in nodes) nodes[n][this.orderName] = n;
                });
        };
        // 删除节点
        this.deleteNode = function(node) {
            $(this.tree).tree('remove', node.target);
        };
        // 清除所有节点
        this.clear = function() {
            $(this.tree).tree('loadData', []);
        };
        // 初始化tree
        this.init = function(url, pid) {
            this.url2Load = url;
            this.tree = $('#' + this.app + 'Tree').tree(this.opt);
            $(this.tree).tree({ loadFilter: this.onFilter });
            $(this.tree).tree("url", this.url2Load.replace(new RegExp("\\{0\\}"), pid));
        };
        // 初始化tree
        this.load = function(data) {
            this.tree = $('#' + this.app + 'Tree').tree(this.opt);
            $(this.tree).tree({ loadFilter: this.onFilter });
            $(this.tree).tree("loadData", data);
        };
        // 初始化tree
        this.ajax = function(url, data) {
            this.tree = $('#' + this.app + 'Tree').tree(this.opt);
            $(this.tree).tree({ loadFilter: this.onFilter });
            var t = this.tree;
            AjaxPostData(url, data, function (result) {
                $(t).tree("loadData", result);
            });
        };
    }

    var tree = new tree(option);
    tree.instance = tree;
    return tree
}
//VonTree1 = function (option) {
//    class _class {
//        #opt = null;
//        #url2Load = "";
//        #onFilter(data) {
//            var opt = $(this).tree("options");
//            function splitData(arr) {
//                for (var a of arr) {
//                    a.id = a[opt.keyName];
//                    a.text = a[opt.treeField];
//                    if (opt.iconField != "") a.iconCls = opt.icons[a[opt.iconField]];
//                    if (a.children != undefined) splitData(a.children);
//                }
//            }
//            splitData(data);
//            return data;
//        };
//        constructor(options) {
//            this.#opt = options;
//            this.instance = null;
//            this.app = options.app;
//        }
//        get currentNode() { return $(this.tree).tree('getSelected'); }
//        // 初始化tree
//        init(url, pid) {
//            this.#url2Load = url;
//            this.tree = $('#' + this.app + 'Tree').tree(this.#opt);
//            $(this.tree).tree({ loadFilter: this.#onFilter });
//            $(this.tree).tree("url", this.#url2Load.replace(new RegExp("\\{0\\}"), pid));
//        };
//        // 初始化tree
//        load(data) {
//            this.tree = $('#' + this.app + 'Tree').tree(this.#opt);
//            $(this.tree).tree({ loadFilter: this.#onFilter });
//            $(this.tree).tree("loadData", data);
//        };
//        // 初始化tree
//        ajax(url, data) {
//            this.tree = $('#' + this.app + 'Tree').tree(this.#opt);
//            $(this.tree).tree({ loadFilter: this.#onFilter });
//            var t = this.tree;
//            AjaxPostData(url, data, function (result) {
//                $(t).tree("loadData", result);
//            });
//        };
//        // 获取同级节点集合
//        selectNode(node) {
//            $(this.tree).tree("select", node.target);
//        }
//        // 获取同级节点集合
//        getSiblings(node) {
//            var pnode = $(this.tree).tree('getParent', node.target);
//            if (pnode === null) return $(this.tree).tree('getRoots');
//            else return this.getChildren(pnode);
//        };
//        // 获取下级节点集合
//        getChildren(node) {
//            var subNodes = [];
//            var t = this.tree;
//            $(node.target).next().children().children("div.tree-node").each(function () {
//                subNodes.push($(t).tree('getNode', this));
//            });
//            return subNodes;
//        };
//        // 获取父级节点集合
//        getParent(node) {
//            return $(this.tree).tree('getParent', node.target);
//        };
//        // 获取节点层级
//        getLevel(node) {
//            var l = $(node[this.#opt.keyName]).parentsUntil("ul.tree", "ul");
//            return l.length + 1;
//        };
//        // 更新当前节点
//        updateNode(node, data) {
//            $(this.tree).tree('update', {
//                target: node.target, text: data[this.#opt.treeField]
//            });
//        };
//        // 在id节点后添加一个新节点
//        appendNode(node, data) {
//            if (node == null) $('#' + this.app + 'Tree').tree('append', { data: data });
//            else $(this.tree).tree('append', { parent: node.target, data: data });
//        };
//        // 移动当前节点位置，url:更新网址，way:移动方向（up,down,left,right）
//        moveNode(url, way) {
//            var node = this.currentNode;
//            var nodes = this.getSiblings(node);
//            var data = { ID: node[this.keyName] };
//            if (way == "up") {
//                if (node[this.orderName] == 0) return;
//                data[this.orderName] = node[this.orderName] - 1;
//                data[this.parentName] = node[this.parentName];
//            } else if (way == "down") {
//                if (node[this.orderName] >= nodes.length) return;
//                data[this.orderName] = node[this.orderName] + 1;
//                data[this.parentName] = node[this.parentName];
//            } else if (way == "left") {
//                var pnode = this.getParent(node);
//                if (pnode == null) return;
//                data[this.orderName] = 0;
//                data[this.parentName] = pnode[this.parentName];
//            } else if (way == "right") {
//                if (node == null || node[this.orderName] == 0) return;
//                data[this.orderName] = 0;
//                data[this.parentName] = nodes[nodes.indexOf(node) - 1][this.keyName];
//            }
//            AjaxPostData(url, data,
//                function (result) {
//                    node[this.orderName] = result[this.orderName];
//                    node[this.parentName] = result[this.parentName];
//                    if (way == "up") {
//                        var previous = nodes[nodes.indexOf(node) - 1];
//                        var n2 = $(this.tree).treegrid("pop", node[this.keyName]);
//                        $(this.tree).treegrid("insert", { before: previous[this.keyName], data: n2 });
//                        $(this.tree).treegrid("select", node[this.keyName]);
//                    } else if (way == "down") {
//                        var n2 = $(this.tree).treegrid("pop", nodes[nodes.indexOf(node) + 1][this.keyName]);
//                        $(this.tree).treegrid("insert", { before: node[this.keyName], data: n2 });
//                    } else if (way == "left") {
//                        var n2 = $(this.tree).treegrid("pop", node[this.keyName]);
//                        n2[this.orderName] = result[this.orderName];
//                        $(this.tree).treegrid("append", { parent: pnode[this.parentName], data: [n2] });
//                    } else if (way == "right") {
//                        var idx = nodes.indexOf(node);
//                        var n2 = $(this.tree).treegrid("pop", node[this.keyName]);
//                        n2[this.orderName] = result[this.orderName];
//                        $(this.tree).treegrid("append", { parent: nodes[idx - 1][this.keyName], data: [n2] });
//                    }
//                    for (var n in nodes) nodes[n][this.orderName] = n;
//                    nodes = this.getSiblings(node);
//                    for (var n in nodes) nodes[n][this.orderName] = n;
//                });
//        };
//        // 删除节点
//        deleteNode(node) {
//            $(this.tree).tree('remove', node.target);
//        };
//        // 清除所有节点
//        clear() {
//            $(this.tree).tree('loadData', []);
//        };
//    }
//    var tree = new _class(option);
//    tree.instance = tree;
//    return tree
//}
/*  使用 html5 提供的 localStorage来缓存数据 */
VonStorage = function () {
    var storageSplitChar = String.fromCharCode(5);
    var localStorage = window.localStorage;
    var DATA_PROCESS_MAPPING = {
        'number': {
            save: function (data) { return data; },
            parse: function (data) { return Number.parseFloat(data); }
        },
        'object': {
            save: function (data) { return JSON.stringify(data); },
            parse: function (data) { return JSON.parse(data); }
        },
        'undefined': {
            save: function (data) { return data; },
            parse: function (data) { return undefined; }
        },
        'default': {
            save: function (data) { return data; },
            parse: function (data) { return data; }
        }
    };
    var storage = new function (type) {
        var getProcess = function (type) {
            return DATA_PROCESS_MAPPING[type] || DATA_PROCESS_MAPPING['default'];
        };
        this.read = function (key) {
            var stringData = localStorage.getItem(key);
            if (stringData) {
                var dataArray = stringData.split(storageSplitChar);
                var data;
                var now = Date.now();
                if (dataArray.length > 2 && dataArray[2] < now) { // 缓存过期
                    localStorage.removeItem(key);
                    return null;
                } else {
                    var value = decodeURIComponent(dataArray[1]);
                    data = getProcess(dataArray[0]).parse(value);
                    return data;
                }
            }
            return null;
        };
        this.write = function (key, value, expired) { // expired 过期时间 单位秒
            var type = typeof value;
            var process = getProcess(type);
            if (!expired) { // 默认不传 不过期
                value = type + storageSplitChar + encodeURIComponent(process.save(value));
            } else {
                var time = expired * 1000 + new Date().getTime();
                value = type + storageSplitChar + process.save(value) + storageSplitChar + time;
            }
            localStorage.setItem(key, value);
        };
        this.clear = function () {
            localStorage.clear();
        };
        this.remove = function (key) {
            localStorage.removeItem(key);
        };
    };
    return storage;
}
/*  在页面上画热力图 */
VonHotspot = function (c) {
    var von = function (canvas) {
        this.max = 100;
        this.min = 4;
        this.canvas = document.getElementById(canvas);
        if (this.canvas.getContext) {
            this.context = this.canvas.getContext("2d");
        } else {
            alert('浏览器不支持canvas!');
        }
        this.drawData = function (x, y, r) {
            this.context.beginPath();
            this.context.arc(x, y, r, 0, 2 * Math.PI);
            this.context.closePath();
            // 创建渐变色: r,g,b取值比较自由，我们只关注alpha的数值
            var radialGradient = this.context.createRadialGradient(x, y, 0, x, y, 120);
            radialGradient.addColorStop(0.0, "rgba(255,0,0," + r / this.max + ")");
            radialGradient.addColorStop(1.0, "rgba(255,0,0,0)");
            this.context.fillStyle = radialGradient;
            // 设置globalAlpha: 需注意取值需规范在0-1之间
            var globalAlpha = (r - this.min) / (this.max - this.min);
            this.context.globalAlpha = Math.max(Math.min(globalAlpha, 1), 0);
            // 填充颜色
            this.context.fill();
        };
        this.drawDatas = function (datas) {
            for (i in datas) {
                if (datas[i].r > this.max) this.max = datas[i].r;
                if (datas[i].r < this.min) this.min = datas[i].r;
            }
            for (i in datas) {
                this.drawData(datas[i].x, datas[i].y, datas[i].r);
            }
        };
        this.drawRect = function (x, y, w, h, r) {
            this.context.beginPath();
            this.context.arc(x + w / 2, y + h / 2, r, 0, 2 * Math.PI);
            this.context.closePath();
            // 创建渐变色: r,g,b取值比较自由，我们只关注alpha的数值
            var radialGradient = this.context.createRadialGradient(x + w / 2, y + h / 2, 0, x + w / 2, y + h / 2, 120);
            radialGradient.addColorStop(0.0, "rgba(255,0,0," + r / this.max + ")");
            radialGradient.addColorStop(1.0, "rgba(255,0,0,0)");
            this.context.fillStyle = radialGradient;
            // 设置globalAlpha: 需注意取值需规范在0-1之间
            var globalAlpha = (r - this.min) / (this.max - this.min);
            this.context.globalAlpha = Math.max(Math.min(globalAlpha, 1), 0);
            // 填充颜色
            this.context.fill();
        };
        this.drawRects = function (rects) {
            for (i in rects) {
                if (rects[i].r > this.max) this.max = rects[i].r;
                if (rects[i].r < this.min) this.min = rects[i].r;
            }
            for (i in rects) {
                this.drawRect(rects[i].x, rects[i].y, rects[i].w, rects[i].h, rects[i].r);
            }
        };
    };
    return new von(c);
}
function ChangeSkin(skin) {
    AjaxPostData("/Service/Execute/81E437E0-D92F-4406-89FC-4970028C1369", { skin: skin }, function (data) { location.reload(); });
}
function initHtmlDeveloperEditor(editor, uploadPath) {
    return CKEDITOR.replace(editor, {
        height: 240,
        toolbarGroups: [
            { name: 'document', groups: ['mode', 'document', 'doctools'] },
            { name: 'clipboard', groups: ['clipboard', 'undo'] },
            '/',
            { name: 'editing', groups: ['find', 'selection', 'spellchecker', 'editing'] },
            { name: 'forms', groups: ['forms'] },
            '/',
            { name: 'basicstyles', groups: ['basicstyles', 'cleanup'] },
            { name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi', 'paragraph'] },
            { name: 'links', groups: ['links'] },
            { name: 'insert', groups: ['insert'] },
            '/',
            { name: 'styles', groups: ['styles'] },
            { name: 'colors', groups: ['colors'] },
            { name: 'tools', groups: ['tools'] },
            { name: 'others', groups: ['others'] },
            { name: 'about', groups: ['about'] }
        ],
        filebrowserImageUploadUrl: '/Home/UploadImageUrl/' + (uploadPath === undefined ? "uploaded" : uploadPath),
        allowedContent : true
    });
}
function initHtmlAdvanceEditor(editor) {
    return CKEDITOR.replace(editor, {
        height: 240,
        toolbarGroups: [
            { name: 'document', groups: ['mode', 'document', 'doctools'] },
            { name: 'clipboard', groups: ['clipboard', 'undo'] },
            { name: 'editing', groups: ['find', 'selection', 'editing'] },
            '/',
            { name: 'basicstyles', groups: ['basicstyles', 'cleanup'] },
            { name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi', 'paragraph'] },
            { name: 'links', groups: ['links'] },
            { name: 'insert', groups: ['insert'] },
            '/',
            { name: 'styles', groups: ['styles'] },
            { name: 'colors', groups: ['colors'] },
            { name: 'tools', groups: ['tools'] }
        ]
    });
}
function initHtmlSimpleEditor(editor) {
    return CKEDITOR.replace(editor, {
        height: 240,
        toolbarGroups: [
            { name: 'document', groups: ['document', 'doctools'] },
            { name: 'clipboard', groups: ['clipboard', 'undo'] },
            '/',
            { name: 'paragraph', groups: ['list', 'indent', 'blocks', 'align', 'bidi', 'paragraph'] },
            { name: 'links', groups: ['links'] },
            { name: 'insert', groups: ['insert'] },
            '/',
            { name: 'styles', groups: ['styles'] },
            { name: 'colors', groups: ['colors'] },
            { name: 'tools', groups: ['tools'] }
        ]
    });
}
function cancelHtmlEditor(editor) {
    editor.updateElement();
    editor.destroy();
    editor = null;
}
// 图片查阅模块，系统会自动根据窗口大小自动放缩图片
function imgShowModal(tagID, data) {
    var div = $("#" + tagID);
    $(div).empty();
    $(div).append("<div style=\"position:absolute;\">");
    var innerdiv = $(div).children()[0];
    var src = (data.indexOf("data:image/") == 0) ? data : "data:image/jpeg;base64," + data;
    $(innerdiv).append("<img style=\"border:5px solid #fff;\" src=\"" + src + "\" style=\"max-width:1024px;\" />");        /*获取当前点击图片的真实大小，并显示弹出层及大图*/
    var img = $(innerdiv).children()[0];
    $(img).attr("src", src).load(function () {
        var windowW = $(window).width();    //获取当前窗口宽度
        var windowH = $(window).height();   //获取当前窗口高度
        var realWidth = this.width;         //获取图片真实宽度
        var realHeight = this.height;       //获取图片真实高度
        var imgWidth, imgHeight;
        var scale = 0.8;                    //缩放尺寸，当图片真实宽度和高度大于窗口宽度和高度时进行缩放
        if (realHeight > windowH * scale) { //判断图片高度
            imgHeight = windowH * scale;    //如大于窗口高度，图片高度进行缩放
            imgWidth = imgHeight / realHeight * realWidth;//等比例缩放宽度
            if (imgWidth > windowW * scale) //如宽度扔大于窗口宽度
                imgWidth = windowW * scale; //再对宽度进行缩放
        } else if (realWidth > windowW * scale) {//如图片高度合适，判断图片宽度
            imgWidth = windowW * scale;//如大于窗口宽度，图片宽度进行缩放
            imgHeight = imgWidth / realWidth * realHeight;//等比例缩放高度
        } else {//如果图片真实高度和宽度都符合要求，高宽不变
            imgWidth = realWidth;
            imgHeight = realHeight;
        }
        $(this).css("width", imgWidth);//以最终的宽度对图片缩放

        var w = (windowW - imgWidth) / 2;//计算图片与窗口左边距
        var h = (windowH - imgHeight) / 2;//计算图片与窗口上边距
        $(innerdiv).css({ "top": h, "left": w });//设置#innerdiv的top和left属性
        $(div).fadeIn("fast");//淡入显示#outerdiv及.pimg
    });
    $(div).click(function () {//再次点击淡出消失弹出层
        $(this).fadeOut("fast");
    });
}
// 读取浏览器Cookies值，支持路径（以点间隔）查询，例如：read("user.name"),write("user.display","von")
VonCookie = function (name) {
    var cookie = function (app) {
        this.app = app;
        this.data = {};
        this.read = function (key) {
            var ks = key.split('.');
            var result = this.data;
            for (var k of ks) {
                result = result[k];
                if (result == null) return null;
            }
            return result;
        }
        this.write = function (key, value) {
            var ks = key.split('.');
            var p = this.data;
            for (var i = 0; i < ks.length - 1; i++) {
                var result = p[ks[i]];
                if (result == null) {
                    var obj = {};
                    p[ks[i]] = obj;
                    p = obj;
                } else p = result;
            }
            p[ks[ks.length - 1]] = value;
            var date = new Date(); //获取当前时间
            date.setTime(date.getTime() + 7 * 24 * 3600 * 1000);
            document.cookie = app + "=" + encodeURIComponent(JSON.stringify(this.data)) + ";expires=" + date.toGMTString();
        }
    }
    var result = new cookie(name);
    var cookies = document.cookie ? document.cookie.split('; ') : [];
    for (var c of cookies) {
        var cs = c.split('=');
        if (cs[0] == name) {
            result.data = JSON.parse(decodeURIComponent(cs[1])); break;
        }
    }
    return result;
}